package cn.truistic.enmicromsg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import cn.truistic.enmicromsg.R;

/**
 * Created by admin on 2018/6/15.
 */

public class MyAdapter extends BaseAdapter {
    private Context context;
    private List<Map<String, Object>> listItem;

    public MyAdapter(Context context ,List<Map<String, Object>> listItem ) {
        this.context = context;
        this.listItem = listItem;
    }

    @Override
    public int getCount() {
        return listItem.size();
    }

    @Override
    public Object getItem(int position) {
        return listItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_item, null);
        }
        try{
            ImageView imageView = (ImageView) convertView.findViewById(R.id.iv_item);
            TextView textView = (TextView) convertView.findViewById(R.id.tv_item);
            Map<String, Object> map = listItem.get(position);
            imageView.setImageResource((Integer) map.get("ItemImage"));
            textView.setText(map.get("ItemText") + "");
        }catch (Exception e){

        }

        return convertView;
    }
}
